package thinkingJava.chapter16;

import java.util.Arrays;

import thinkingJava.chapter15.Generator;

public class ArraySearching {
	public static void main(String[] args) {
		Generator<Integer> gen =
			new RandomGenerator.Integer(1000);
		Integer[] ia = new Integer[25];
		for (int i = 0; i < ia.length; i ++) {
			ia[i] = gen.next();
		}
		int[] a = ConvertTo.primitive(ia);
		Arrays.sort(a);
		System.out.println("Sorted  array : " + Arrays.toString(a));
		while(true) {
			int r = gen.next();
			int location = Arrays.binarySearch(a, r);
			if (location >= 0 ) {
				System.out.println("location of " + r + " is " + location + ", a[" + location + "]=" + a[location]);
				break;
			}
		}
	}
}
